﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CWB.Common.Constant;
using System.Data.SQLite;

namespace CWB.Web.Models
{
    public class DBSortingPara
    {
        public DBSortingPara() { }
        public List<DBSortingItem> Sorting = new List<DBSortingItem>() { };

        public void AddSortingItem(string columnName, SortingType sortingType)
        {
            Sorting.Add(new DBSortingItem() { ColumnName = columnName, SortingBy = sortingType });
        }

        public void AddSortingItem(string columnName)
        {
            Sorting.Add(new DBSortingItem() { ColumnName = columnName, SortingBy = SortingType.Desc });
        }

        public string getOrderByHLQ()
        {
            string rtn = default(string);
            if (Sorting.Count > 0)
            {
                string[] arrSortingBy = { "" };
                List<string> lSortingBy = new List<string>() { };
                foreach (DBSortingItem dbsi in Sorting)
                {
                    lSortingBy.Add(string.Format("{0} {1}", dbsi.ColumnName, dbsi.SortingBy.ToString()));
                }
                rtn = string.Join(", ", lSortingBy.ToArray());
                rtn = string.Format(" order by {0} ", rtn);
            }
            return rtn;
        }
    }

    public class DBSortingItem
    {
        public string ColumnName { get; set; }
        public SortingType SortingBy { get; set; }
    }
}
